<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../css/mui.min.css">
		<link rel="stylesheet" href="../style/fjol_style.css" />
	</head>

	<body>
		<!--下拉刷新容器-->
		
		<div id="pullrefresh" class="mui-content mui-scroll-wrapper">
			<div class="mui-scroll">
				<!--数据列表-->
				<ul class="mui-table-view" id="recommendList">
					
				</ul>
			</div>
		</div> 
		<script src="../js/mui.min.js"></script>
		<script src="../js/md5.js"></script>
		<script src="../js/common.util.js"></script>
		<script src="../js/network.js"></script>
		<script src="../js/mui.pullToRefresh.js"></script>
		<script src="../js/mui.pullToRefresh.material.js"></script>
		<!--<script src="js/fj_public_js.js"></script>-->
		<script>
			mui.init({
				pullRefresh: {
					container: '#pullrefresh',
					down: {
						callback: pulldownRefresh
					},
					up: {
						contentrefresh: '正在加载...',
						callback: pullupRefresh
					}
				}
			});
			
				var pageValue =1;
		/**
			 * 下拉刷新具体业务实现
			 */
			function pulldownRefresh() {
				setTimeout(function(){
					dataLoad(1,10);
					mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
					return pageValue = 1;
				},1000);
				
			}	
			/**
			 * 上拉加载具体业务实现
			 */
			
			function pullupRefresh() {
				setTimeout(function() {

				var userInfo = common.myStorage.getItem('userInfo');
				pageValue++;
				var count;
//				console.log(pageValue);
					mui('#pullrefresh').pullRefresh().endPullupToRefresh((count==0));
				
					var param = [{
						key:'clientId',
						value:userInfo.clientId
					},{
						key:'page',
						value:pageValue
					},{
						key:'rows',
						value:10
					}];
					fjNetwork.get('fjzx/client/house-bargain-list.json',param,function(data){
//					console.log(JSON.stringify(data));
					var rows = data.rows;
					
					count = rows.length;
					mui('#pullrefresh').pullRefresh().endPullupToRefresh((rows.length==0)); //参数为true代表没有更多数据了。
					
					var recommendList = document.querySelector('#recommendList');
					var recommendArr = new Array();
					for (i in rows) {
						var li = document.createElement('li');	//创建一个li标签
						li.className = 'mui-table-view-cell';	//设置class
						li.setAttribute('id',rows[i].id);
				        recommendArr.push('<div class="mui-clearfix mb10">');
		            	recommendArr.push(rows[i].title);
		            	recommendArr.push('</div>');
		                recommendArr.push('<span class=" mui-pull-right f08" style="color: #4889c1;">');
		                    recommendArr.push('房源详情');
		                    recommendArr.push('<span class="mui-icon mui-icon-arrowright f12"></span>');
		                recommendArr.push('</span>');
		                recommendArr.push('<div class="mui-media-body" style="line-height: 1.6em;">');
		                    
		                    recommendArr.push('<div class="mui-ellipsis">');
		                    	recommendArr.push('<p class="mui-inline mr10">房东售价</p><span>'+parseInt(rows[i].totalPrice/10000)+'万</span><br />');
		                    	recommendArr.push('<p class="mui-inline mr10">我的出价</p>');
		                    	recommendArr.push('<span class="mui-badge mui-badge-primary mui-badge-inverted f12">'+parseInt(rows[i].bargainPrice)+'万</span>');
		                    	recommendArr.push('<em class="color9">('+parseFloat(rows[i].bargainPrice*1000/(rows[i].totalPrice)*100).toFixed(1)+'折)</em>');
		                    recommendArr.push('</div>');
		                recommendArr.push('</div>');
					li.innerHTML = recommendArr.join('');
					recommendList.appendChild(li);
					}
					
				
				},function(msg){
//					console.log(msg);
				});
				
				},1000);
			}
			mui.plusReady(function(){
				
					mui('#recommendList').on('tap','li',function(){
//						console.log(this.getAttribute('id'));
						mui.openWindow({
						url:'../house_detail.html',
						id:'house_detail',
						extras:{
							houseId:this.getAttribute('id'),
							parentid:'cut_price_record'
						}
					})
					});
			dataLoad(1,10);
				
				
			});
				function dataLoad(pageValue,rowsNumber){

					var userInfo = common.myStorage.getItem('userInfo');
					var param = [{
						key:'clientId',
						value:userInfo.clientId
					},{
						key:'page',
						value:pageValue
					},{
						key:'rows',
						value:10
					}];
					fjNetwork.get('fjzx/client/house-bargain-list.json',param,function(data){
//					console.log(JSON.stringify(data));
					var rows = data.rows;
					var recommendList = document.querySelector('#recommendList');
					var recommendArr = new Array();
					for (i in rows) {
						recommendArr.push('<li class="mui-table-view-cell mui-media" id="'+rows[i].id+'">');
		            	recommendArr.push('<div class="mui-clearfix mb10">');
		            	recommendArr.push(rows[i].title);
		            	recommendArr.push('</div>');
		                recommendArr.push('<span class=" mui-pull-right f08" style="color: #4889c1;">');
		                    recommendArr.push('房源详情');
		                    recommendArr.push('<span class="mui-icon mui-icon-arrowright f12"></span>');
		                recommendArr.push('</span>');
		                recommendArr.push('<div class="mui-media-body" style="line-height: 1.6em;">');
		                    
		                    recommendArr.push('<div class="mui-ellipsis">');
		                    	recommendArr.push('<p class="mui-inline mr10">房东售价</p><span>'+parseInt(rows[i].totalPrice/10000)+'万</span><br />');
		                    	recommendArr.push('<p class="mui-inline mr10">我的出价</p>');
		                    	recommendArr.push('<span class="mui-badge mui-badge-primary mui-badge-inverted f12">'+parseInt(rows[i].bargainPrice)+'万</span>');
		                    	recommendArr.push('<em class="color9">('+parseFloat(rows[i].bargainPrice*1000/(rows[i].totalPrice)*100).toFixed(1)+'折)</em>');
		                    recommendArr.push('</div>');
		                recommendArr.push('</div>');
		            recommendArr.push('</li>');
		                
					}
					recommendList.innerHTML = recommendArr.join('');
					
					
				
				},function(msg){
					mui.toast(msg);
				});
				}
			
			Date.prototype.toLocaleString = function() {
		        return this.getFullYear() + "-" + (this.getMonth() + 1) + "-" + this.getDate() + " " + this.getHours() + ":" + this.getMinutes() + ":" + this.getSeconds();
		    };
			
		</script>
	</body>

</html>